package com.tbm.prode.actions;

import java.util.logging.Logger;

import com.opensymphony.xwork2.ActionSupport;
import com.tbm.prode.model.User;
import com.tbm.prode.services.TBMServiceFactory;
import com.tbm.prode.services.UserService;

public class Login extends ActionSupport{
	
	private static final long serialVersionUID = 1L;
	private static final Logger log = Logger.getLogger(Login.class.getName());

	private String username;
	private String password;
	private User user;
	
	public String execute() throws Exception {
		
		log.info("Login try " + username + " " + password);
		UserService userService = TBMServiceFactory.getUserService();
		User user = userService.authenticate(username, password);
		
		if(user != null){
			return SUCCESS;			
		}else{
			return INPUT;
		}
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	
}
